//
//  DLCircleListViewController.m
//  FRP_OC
//
//  Created by DeLongYang on 2017/11/2.
//  Copyright © 2017年 DeLongYang. All rights reserved.
/*
    参照的简书是： http://www.jianshu.com/p/3beb21d5def2
    这是纯代码布局 演示一下 MVVM 的设计
 */

#import "DLCircleListViewController.h"
#import "DLCircleListView.h"
#import "DLCircleListViewModel.h"   //
#import "DLViewController.h"

@interface DLCircleListViewController ()

@property (nonatomic,strong)DLCircleListView *mainView;

@property (nonatomic,strong)DLCircleListViewModel *viewModel;

@end

@implementation DLCircleListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - system
- (void)updateViewConstraints {

    WS(weakSelf)

    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.edges.equalTo(weakSelf.view);
    }];

    [super updateViewConstraints];
}

#pragma mark - private
- (void)dl_addSubviews {

    [self.view addSubview:self.mainView];
}

- (void)dl_bindViewModel {

    @weakify(self);
    [[self.viewModel.cellClickSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {

        @strongify(self);
        DLViewController *circleMainVC = [[DLViewController alloc] init];
        [self.navigationController pushViewController:circleMainVC animated:YES];
    }];
}

- (void)dl_layoutNavigation {
    
    self.title = @"社团列表";
}

#pragma mark - layzLoad
- (DLCircleListView *)mainView {
    
    if (!_mainView) {
        
        _mainView = [[DLCircleListView alloc] initWithViewModel:self.viewModel];
    }
    
    return _mainView;
}

- (DLCircleListViewModel *)viewModel {
    
    if (!_viewModel) {
        
        _viewModel = [[DLCircleListViewModel alloc] init];
    }
    
    return _viewModel;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
